package ren.xxpure.service.impl;

import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import ren.xxpure.dao.UserRepository;
import ren.xxpure.entity.LoginUser;
import ren.xxpure.entity.User;

import javax.annotation.Resource;
import java.util.Objects;

@Service
public class UserDetailServiceImpl implements UserDetailsService {
	@Resource
	UserRepository userRepository;

	@Override
	public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
		User userByUserName = userRepository.findUserByUserName(s);
		if (Objects.isNull(userByUserName)) {
			throw new RuntimeException("用户不存在");
		}
		return new LoginUser(userByUserName);
	}
}
